#ifndef _MASTER_H_
#define _MASTER_H_

#include "EventProcessor.h"
#include "EventProcessorImp.h"
#include "Message.h"
#include "DistributedCounter.h"
#include "Worker.h"
#include "TwoWayList.h"
#include <string>
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;



class MasterImp : public EventProcessorImp {
private:

  string wordToSearch;
 
  vector<string> lines;
 
  int currentLine;

  int counter;
 
  ifstream myfile;

  TwoWayList<EventProcessor> myWorkers;

  int ReadNextLine(string& line);

  void CheckAndSend(EventProcessor& sender);	
	
  MasterImp(string wordToSearch,char *fileName);
  	
  MESSAGE_HANDLER_DECLARATION(SearchDone);

  MESSAGE_HANDLER_DECLARATION(WorkerDone);

  MESSAGE_HANDLER_DECLARATION(WorkerReady);
	
  MESSAGE_HANDLER_DECLARATION(Die);

  friend class Master;
};

// Interface class
class Master : public EventProcessor {
public:
  Master(string wordToSearch, char *fileName);
};

inline Master::Master(string wordToSearch, char *fileName){
	evProc = new MasterImp(wordToSearch,fileName);
}

#endif 
